/* GUI CONVERTED from sqqorp08.p (converter v1.76) Tue May 20 03:49:46 2003 */
/* sqqorp08.p - QUOTE GROSS MARGIN REPORT BY QUOTE NUMBER                     */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.13 $                                                           */
/*V8:ConvertMode=FullGUIReport                                                */
/* REVISION: 4.0      LAST MODIFIED: 12/12/88   BY: jms  *A548*               */
/*                                   01/13/89   by: jms  *A606*               */
/* REVISION: 5.0      LAST MODIFIED: 03/21/89   by: RL   *B051*               */
/*                                   07/10/89   by: jms  *BXXX*               */
/* REVISION: 6.0      LAST MODIFIED: 04/20/90   BY: ftb                       */
/* REVISION: 7.0      LAST MODIFIED: 03/17/92   BY: TMD *F264*                */
/* REVISION: 7.0      LAST MODIFIED: 03/27/92   BY: dld *F326*                */
/* REVISION: 7.3      LAST MODIFIED: 01/04/92   BY: afs *G500*                */
/* REVISION: 7.3      LAST MODIFIED: 04/10/96   BY: jzw *G1P6*                */
/* REVISION: 8.6      LAST MODIFIED: 10/22/97   BY: ays *K148*                */
/* REVISION: 8.6      LAST MODIFIED: 11/25/97   BY: *H1GX* Seema Varma        */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 06/11/98   BY: *L02K* Russ Witt          */
/* REVISION: 8.6E     LAST MODIFIED: 08/07/98   BY: *L05K* Russ Witt          */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KN* Mark Brown         */
/* REVISION: 9.1      LAST MODIFIED: 11/20/00   BY: *N0TW* Jean Miller        */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.12     BY: Hareesh V           DATE: 06/21/02  ECO: *N1HY*    */
/* $Revision: 1.13 $    BY: Deepak Rao           DATE: 05/20/03  ECO: *P0SG*    */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/


/*GUI global preprocessor directive settings */
&GLOBAL-DEFINE PP_PGM_RP TRUE
&GLOBAL-DEFINE PP_ENV_GUI TRUE


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "2+ "}

define variable cust            like qo_cust                           no-undo.
define variable cust1           like qo_cust                           no-undo.
define variable nbr             like qo_nbr                            no-undo.
define variable nbr1            like qo_nbr                            no-undo.
define variable ord             like qo_ord_date                       no-undo.
define variable ord1            like qo_ord_date                       no-undo.
define variable expdate         like qo_exp_date                       no-undo.
define variable expdate1        like qo_exp_date                       no-undo.
define variable name            like ad_name                           no-undo.
define variable ext_price       like qod_price label "Ext Price"
                                format "->,>>>,>>>,>>9.99<<<<"         no-undo.
define variable gr_margin       like qod_price label "Unit Margin"     no-undo.
define variable ext_gr_margin   like gr_margin label "Ext Margin"
                                format "->,>>>,>>>,>>9.99<<<<"         no-undo.
define variable desc1           like pt_desc1                          no-undo.
define variable include_lost    like mfc_logical initial no
                                label "Include Lost"                   no-undo.
define variable qty_open        like qod_rel_chg                       no-undo.
define variable base_price      like sod_price                         no-undo.
define variable base_cost       like sod_std_cost                      no-undo.
define variable base_rpt        like so_curr                           no-undo.
define variable disp_curr       as   character format "x(1)" label "C" no-undo.
define variable mc-error-number like msg_nbr                           no-undo.
define variable o_disp_line1    as   character format "x(40)"          no-undo.
define variable o_disp_line2    as   character format "x(40)"          no-undo.
define variable plines          as   integer                           no-undo.
define variable rndmthd         like rnd_rnd_mthd                      no-undo.
define variable disp-text       as   character format "x(15)"          no-undo.

/* DATA DEFINITIONS FOR TRIANGULATION LIBRARY ROUTINES */
{gprunpdf.i "mcpl" "p"}
{gprunpdf.i "mcui" "p"}


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
nbr          colon 15  nbr1     label  "To" colon 49
   cust         colon 15  cust1    label  "To" colon 49
   ord          colon 15  ord1     label  "To" colon 49
   expdate      colon 15  expdate1 label  "To" colon 49
   include_lost colon 15
   base_rpt     colon 15
 SKIP(.4)  /*GUI*/
with frame a side-labels width 80 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER.
 F-a-title = &IF (DEFINED(SELECTION_CRITERIA) = 0)
  &THEN " Selection Criteria "
  &ELSE {&SELECTION_CRITERIA}
  &ENDIF .
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame a =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame a + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5. /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

expdate = today.

/* GET ROUNDING METHOD FOR BASE CURRENCY  */
{gprunp.i "mcpl" "p" "mc-get-rnd-mthd"
   "(input  base_curr,
     output rndmthd,
     output mc-error-number)"}

{wbrp01.i}

/*GUI*/ {mfguirpa.i true "printer" 132 " " " " " "  }

/*GUI repeat : */
/*GUI*/ procedure p-enable-ui:


   if nbr1 = hi_char
   then
      nbr1 = "".

   if cust1 = hi_char
   then
      cust1 = "".

   if ord = low_date
   then
      ord = ?.

   if ord1 = hi_date
   then
      ord1 = ?.

   if expdate = low_date
   then
      expdate = ?.

   if expdate1 = hi_date
   then
      expdate1 = ?.

   if c-application-mode <> 'web'
   then
      
run p-action-fields (input "display").
run p-action-fields (input "enable").
end procedure. /* p-enable-ui, replacement of Data-Entry GUI*/

/*GUI*/ procedure p-report-quote:


   {wbrp06.i &command = update
             &fields  = "  nbr          nbr1
                           cust         cust1
                           ord          ord1
                           expdate      expdate1
                           include_lost base_rpt"
             &frm     = "a"}

   if     (c-application-mode <>     'web')
      or  (c-application-mode  =     'web'
      and (c-web-request      begins 'data'))
   then do:

      /* CREATE BATCH INPUT STRING */
      bcdparm = "".
      {mfquoter.i nbr      }
      {mfquoter.i nbr1     }
      {mfquoter.i cust     }
      {mfquoter.i cust1    }
      {mfquoter.i ord      }
      {mfquoter.i ord1     }
      {mfquoter.i expdate  }
      {mfquoter.i expdate1 }
      {mfquoter.i include_lost}
      {mfquoter.i base_rpt }

      if nbr1 = ""
      then
         nbr1 = hi_char.

      if cust1 = ""
      then
         cust1 = hi_char.

      if ord   = ?
      then
         ord = low_date.

      if ord1 = ?
      then
         ord1 = hi_date.

      if expdate = ?
      then
         expdate = low_date.

      if expdate1 = ?
      then
         expdate1 = hi_date.

   end. /* IF (c-application-mode <> 'web').... */

   /* OUTPUT DESTINATION SELECTION */
   
/*GUI*/ end procedure. /* p-report-quote */
/*GUI - Field Trigger Section */

/*GUI MFSELxxx removed*/
/*GUI*/ procedure p-report:
/*GUI*/   {gpprtrpa.i "printer" 132 " " " " " " " " }
/*GUI*/   mainloop: do on error undo, return error on endkey undo, return error:




   {mfphead.i}
   do with frame c width 132:

      /* SET EXTERNAL LABELS */
      setFrameLabels(frame c:handle).

      {hksimsg.i """" """"}        /*fdn*/

      for each qo_mstr
         fields  (qo_cust     qo_exp_date
                  qo_exru_seq qo_ex_rate
                  qo_ex_rate2 qo_nbr
                  qo_ord_date qo_rmks
                  qo_ship     qo_slspsn
                  qo_stat     qo_curr)
         where    qo_nbr      >= nbr     and   qo_nbr      <= nbr1
         and      qo_cust     >= cust    and   qo_cust     <= cust1
         and      qo_ord_date >= ord     and   qo_ord_date <= ord1
         and      qo_exp_date >= expdate and   qo_exp_date <= expdate1
         and     (base_rpt     = ""       or   base_rpt     = qo_curr
                                          or   qo_curr      = "")    AND LOOKUP(qo_site,GLOBAL_user_site) > 0       /*fdn*/
         no-lock
         with frame c width 132:

         /* MAKE SURE THE QUOTE HAS AT LEAST ONE VALID LINE BEFORE DISP */
         if not include_lost
         then do:

            for first qod_det
               fields (qod_desc     qod_line
                       qod_nbr      qod_part
                       qod_price    qod_qty_quot
                       qod_qty_rel  qod_rsn_lost
                       qod_std_cost qod_type
                       qod_um)
               where qod_nbr = qo_nbr
               and   qod_rsn_lost = ""    AND LOOKUP(qod_site,GLOBAL_user_site) > 0       /*fdn*/
               no-lock:
            end. /* FOR FIRST qod_det */

            if not available qod_det
            then
               next.

         end. /* IF NOT include_lost */

         name = "".

         for first ad_mstr
            fields (ad_addr ad_name)
            where ad_addr = qo_cust
         no-lock:
            name = ad_name.
         end. /* FOR FIRST ad_mstr */

         /* CALL mcui.p TO FORMAT OUTPUT LINE */
         do on endkey undo, retry:
            {gprunp.i "mcui" "p" "mc-ex-rate-output"
               "(input  qo_curr,
                 input  base_curr,
                 input  qo_ex_rate,
                 input  qo_ex_rate2,
                 input  qo_exru_seq,
                 output o_disp_line1,
                 output o_disp_line2)"}
         end. /* DO ON ENDKEY */

         plines = 1.

         /* ADD plines TO COUNT LINES NEEDED TO DETERMINE PAGE OVER FLOW */
         if   (o_disp_line2 <> ""
            or qo_slspsn[2] <> "")
         then
            plines = plines + 1.

         if qo_slspsn[3] <> ""
         then
            plines = plines + 1.

         if qo_slspsn[4] <> ""
         then
            plines = plines + 1.

         if qo_rmks <> ""
         then
            plines = plines + 1.

         if page-size - line-counter <= plines
         then
            page.

         do with frame b:
            /* SET EXTERNAL LABELS */
            setFrameLabels(frame b:handle).
            display
               qo_nbr       qo_cust
               name         qo_ship
               qo_ord_date  qo_exp_date
               qo_stat      qo_slspsn[1]
               qo_curr
            with frame b down width 132 no-attr-space STREAM-IO /*GUI*/ .
         end. /* DO WITH */

         /* ADD SALESMAN AND SECOND CURRENCY LINE ON NEW PRINT LINES */
         if    o_disp_line1 <> ""
            or qo_slspsn[2] <> ""
         then
            put
               qo_slspsn[2] at 78
               o_disp_line1 at 87.

         if    o_disp_line2 <> ""
            or qo_slspsn[3] <> ""
         then
            put
               qo_slspsn[3] at 78
               o_disp_line2 at 87.

         if qo_slspsn[4] <> ""
         then
            put qo_slspsn[4] at 78.

         if qo_rmks <> ""
         then
            put qo_rmks at 13.

         /* GET ORDER DETAIL  */
         for each qod_det
            fields (qod_desc     qod_line
                    qod_nbr      qod_part
                    qod_price    qod_qty_quot
                    qod_qty_rel  qod_rsn_lost
                    qod_std_cost qod_type
                    qod_um)
            where qod_nbr = qo_nbr
            by qod_nbr
            by qod_line
            with frame c down width 132:

            assign
               base_price = qod_price
               base_cost  = qod_std_cost
               disp_curr  = "".

            if     base_rpt   = ""
               and base_curr <> qo_curr
            then do:

               /* CONVERT FROM FOREIGN TO BASE CURRENCY */
               {gprunp.i "mcpl" "p" "mc-curr-conv"
                  "(input qo_curr,
                    input base_curr,
                    input qo_ex_rate,
                    input qo_ex_rate2,
                    input base_price,
                    input false, /* DO NOT ROUND */
                    output base_price,
                    output mc-error-number)"}.

               disp_curr = getTermLabel("YES",1).
            end. /* IF base_rpt = "" .... */

            if     base_rpt  <> ""
               and base_curr <> qo_curr
            then
               /* CONVERT FROM BASE TO FOREIGN CURRENCY */
               {gprunp.i "mcpl" "p" "mc-curr-conv"
                  "(input  base_curr,
                    input  qo_curr,
                    input  qo_ex_rate2,
                    input  qo_ex_rate,
                    input  base_cost,
                    input  false, /* DO NOT ROUND */
                    output base_cost,
                    output mc-error-number)"}.

            /* EXCLUDE LOST QUOTES IF SPECIFIED */
            if     include_lost  = no
               and qod_rsn_lost <> ""
            then
               next.

            assign
               qty_open      = qod_qty_quot - qod_qty_rel
               ext_price     = qty_open     * base_price
               gr_margin     = base_price   - base_cost
               ext_gr_margin = qty_open     * gr_margin.

            /* ROUND BASE_PRICE, EXT_PRICE & EXT_GR_MARGIN BASED ON  */
            /* BASE CURRENCY ROUNDING METHOD                         */
            {gprunp.i "mcpl" "p" "mc-curr-rnd"
               "(input-output base_price,
                 input        rndmthd,
                 output       mc-error-number)"}

            if mc-error-number <> 0
            then
               {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}

            {gprunp.i "mcpl" "p" "mc-curr-rnd"
               "(input-output ext_price,
                 input        rndmthd,
                 output       mc-error-number)"}

            {gprunp.i "mcpl" "p" "mc-curr-rnd"
               "(input-output ext_gr_margin,
                 input        rndmthd,
                 output       mc-error-number)"}

            accumulate (ext_price) (total).
            accumulate (ext_gr_margin) (total).

            desc1 = qod_desc.

            for first pt_mstr
               fields (pt_desc1 pt_desc2 pt_part)
               where pt_part = qod_part
            no-lock:
            end. /* FOR FIRST pt_mstr */

            if desc1 = ""
               and available pt_mstr
            then
               desc1 = pt_desc1 + " " + pt_desc2.

            if desc1 <> ""
            then
               if page-size - line-counter < 2
               then
                  page.

            display
               space(3)      qod_line
               qod_part      qod_um
               qod_qty_quot  qod_qty_rel
               qty_open      disp_curr
               base_price    ext_price
               ext_gr_margin qod_type WITH STREAM-IO /*GUI*/ .

            put desc1 at 6 format "x(49)".

            
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/

         end. /* FOR EACH qod_det */

         down 1.
         if page-size - line-counter < 2
         then
            page.

         underline  ext_price ext_gr_margin.
         if base_rpt = ""
         then
            disp-text = getTermLabel("BASE_ORDER_TOTAL",17) + ":".
         else
            disp-text = base_rpt
                      + " "
                      + getTermLabel("ORDER_TOTAL",17)
                      + ":".

         display
            disp-text                   @ qod_part
            accum total (ext_price)     @ ext_price
            accum total (ext_gr_margin) @ ext_gr_margin WITH STREAM-IO /*GUI*/ .

         
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/


      end. /* FOR EACH qo_mstr */

      down 1.
      if page-size - line-counter < 2
      then
         page.

      underline ext_price ext_gr_margin.
      if base_rpt = ""
      then
         disp-text = getTermLabel("BASE_REPORT_TOTALS",18) + ":".
      else
         disp-text = base_rpt + " " +
      getTermLabel("REPORT_TOTALS",17) + ":".

      display
         disp-text                   @ qod_part
         accum total (ext_price)     @ ext_price
         accum total (ext_gr_margin) @ ext_gr_margin WITH STREAM-IO /*GUI*/ .

   end. /* DO WITH FRAME c:*/
   /* REPORT TRAILER */
   
/*GUI*/ {mfguitrl.i} /*Replace mfrtrail*/

/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/

end. /* REPEAT */

{wbrp04.i &frame-spec = a}

/*GUI*/ end procedure. /*p-report*/
/*GUI*/ {mfguirpb.i &flds=" nbr nbr1 cust cust1 ord ord1 expdate expdate1 include_lost base_rpt "} /*Drive the Report*/
